home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / COMMS / C101.ZIP / UUPC11XS.ZIP / UUCICO / DCPSTATS.C < prev    next >
C/C++ Source or Header  |  1992-11-28  |  6KB  |  166 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    File transfer information for UUPC/extended                     */
  3. /*                                                                    */
  4. /*    Copyright (c) 1991, Andrew H. Derbyshire                        */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*                       standard include files                       */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <time.h>
  14. #include <stdlib.h>
  15.  
  16. /*--------------------------------------------------------------------*/
  17. /*                    UUPC/extended include files                     */
  18. /*--------------------------------------------------------------------*/
  19.  
  20. #include "lib.h"
  21. #include "dcp.h"
  22. #include "dcpstats.h"
  23. #include "stater.h"
  24. #include "hlib.h"
  25. #include "hostable.h"
  26. #include "hostatus.h"
  27. #include "security.h"
  28. #include "timestmp.h"
  29.  
  30. /*--------------------------------------------------------------------*/
  31. /*                          Global variables                          */
  32. /*--------------------------------------------------------------------*/
  33.  
  34. currentfile();
  35.  
  36. /*--------------------------------------------------------------------*/
  37. /*    d c s t a t s                                                   */
  38. /*                                                                    */
  39. /*    Report transmission information for a connection                */
  40. /*--------------------------------------------------------------------*/
  41.  
  42. void dcstats(void)
  43. {
  44.    if (hostp == BADHOST)
  45.    {
  46.       printmsg(0,"dcstats: host structure pointer is NULL");
  47.       panic();
  48.    }
  49.  
  50.    if (!equal(rmtname , hostp->hostname))
  51.       return;
  52.  
  53.    if (remote_stats.lconnect > 0)
  54.    {
  55.       time_t connected;
  56.       unsigned long bytes;
  57.       unsigned long bps;
  58.  
  59.       HostStatus();
  60.  
  61.       connected = time(NULL) - remote_stats.lconnect;
  62.       remote_stats.connect += connected;
  63.       bytes = remote_stats.bsent + remote_stats.breceived;
  64.  
  65.       if ( connected > 0 )
  66.          bps = bytes / (long unsigned) connected;
  67.       else
  68.          bps = 0;
  69.  
  70.       printmsg(0,"%ld files sent, %ld files received, "
  71.                  "%ld bytes sent, %ld bytes received",
  72.             remote_stats.fsent, remote_stats.freceived ,
  73.             remote_stats.bsent, remote_stats.breceived);
  74.       printmsg(0, "%ld packets transferred, %ld errors, "
  75.                   "connection time %ld:%02ld, %ld bytes/second",
  76.             (long) remote_stats.packets,
  77.             (long) remote_stats.errors,
  78.             (long) connected / 60L, (long) connected % 60L, bps);
  79.  
  80.    } /*if */
  81.    else
  82.       printmsg(0,"Unable to print information for host %s (%s)",
  83.             rmtname,
  84.             hostp->hostname);
  85.  
  86.    if (remote_stats.lconnect > hostp->hstats->lconnect)
  87.       hostp->hstats->lconnect = remote_stats.lconnect;
  88.  
  89.    if (remote_stats.ltime > hostp->hstats->ltime)
  90.       hostp->hstats->lconnect = remote_stats.lconnect;
  91.  
  92.    hostp->hstats->connect   += remote_stats.connect;
  93.    hostp->hstats->calls     += remote_stats.calls;
  94.    hostp->hstats->fsent     += remote_stats.fsent;
  95.    hostp->hstats->freceived += remote_stats.freceived;
  96.    hostp->hstats->bsent     += remote_stats.bsent;
  97.    hostp->hstats->breceived += remote_stats.breceived;
  98.    hostp->hstats->errors    += remote_stats.errors;
  99.    hostp->hstats->packets   += remote_stats.packets;
  100.  
  101. } /* dcstats */
  102.  
  103. /*--------------------------------------------------------------------*/
  104. /*    d c u p d a t e                                                 */
  105. /*                                                                    */
  106. /*    Update the status of all known hosts                            */
  107. /*--------------------------------------------------------------------*/
  108.  
  109. void dcupdate( void )
  110. {
  111.    boolean firsthost = TRUE;
  112.    struct HostTable *host;
  113.    FILE *stream;
  114.    char fname[FILENAME_MAX];
  115.    long size;
  116.    size_t len1 = strlen(compilep );
  117.    size_t len2 = strlen(compilev );
  118.  
  119.    HostStatus();              /* Get new data, if needed          */
  120.    mkfilename( fname, E_confdir, DCSTATUS );
  121.  
  122.    filebkup( fname );      /* Rename the file if desired       */
  123.  
  124.    if ((stream  = FOPEN(fname, "w", BINARY)) == NULL)
  125.    {
  126.       printerr( fname );
  127.       return;
  128.    }
  129.  
  130.    fwrite( &len1, sizeof len1, 1, stream );
  131.    fwrite( &len2, sizeof len2, 1, stream );
  132.    fwrite( compilep , 1, len1, stream);
  133.    fwrite( compilev , 1, len2, stream);
  134.    fwrite( &start_stats , sizeof start_stats , 1,  stream);
  135.  
  136.    while  ((host = nexthost( firsthost )) != BADHOST)
  137.    {
  138.       len1 = strlen( host->hostname );
  139.       len2 = sizeof *(host->hstats);
  140.  
  141.       firsthost = FALSE;
  142.  
  143.       fwrite( &len1, sizeof len1, 1, stream );
  144.       fwrite( &len2, sizeof len2, 1, stream );
  145.       fwrite( host->hostname , sizeof hostp->hostname[0], len1, stream);
  146.       host->hstats->save_hstatus = ( host->hstatus == called ) ?
  147.                                     succeeded : host->hstatus;
  148.       fwrite( host->hstats , len2, 1,  stream);
  149.    }
  150.  
  151. /*--------------------------------------------------------------------*/
  152. /*         Make we sure got end of file and not an I/O error          */
  153. /*--------------------------------------------------------------------*/
  154.  
  155.    if (ferror( stream ))
  156.    {
  157.       printerr( fname );
  158.       clearerr( stream );
  159.    }
  160.  
  161.    fclose( stream );
  162.  
  163.    hstatus_age = stater( fname , &size );
  164.  
  165. } /* dcupdate */
  166.